package com.zsk.shop.api.idcard;

import com.zsk.shop.common.constant.Constant;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationResponse;

/**
 * @author Ys
 * @version 1.0
 * @date 2021/5/18 11:56
 */
public class IdentityCheck {

    /**
     * @param name   姓名
     * @param idCard 身份证号
     * @return java.lang.String
     * @author Ys
     * @date 2021/5/18 12:07
     */
    public static String idCardVerification(String name, String idCard) {
        String result = "-1";
        try {
            // APPId: 1304611091
            Credential cred = new Credential(Constant.VERIFICATION_SECRET_ID, Constant.VERIFICATION_SECRET_KEY);

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            FaceidClient client = new FaceidClient(cred, "ap-shanghai", clientProfile);

            IdCardVerificationRequest req = new IdCardVerificationRequest();
            req.setIdCard(idCard);
            req.setName(name);

            IdCardVerificationResponse resp = client.IdCardVerification(req);
            result = resp.getResult();
            System.out.println(IdCardVerificationResponse.toJsonString(resp));
            return result;
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
        return result;
    }

}
